<%@ page import="java.io.InputStream" %>
<%@ page import="org.apache.commons.io.IOUtils" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="com.alibaba.fastjson.JSON" %>
<%@ page import="java.util.Map" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String id = request.getParameter("id");
    String name = request.getParameter("name");
    if(id==null) {
        InputStream in = request.getInputStream();
        String jsonstr = IOUtils.toString(in, "utf-8");
        JSONObject jsonobj = JSON.parseObject(jsonstr);
        id = jsonobj.getString("id");
        name = jsonobj.getString("name");
    }
    JSONObject json = new JSONObject();
    Map haohans = (Map) application.getAttribute("haohans");

    if(haohans.containsValue(id)){
        id = request.getParameter("id");
        name = request.getParameter("name");
        haohans.put(id,name);
        json.put("msg","该英雄已修改");
    }else{
        json.put("msg","该英雄不存在");
    }


    json.put("haohans",haohans);
//    out.println(JSON.toJSONString(json, SerializerFeature.WriteSlashAsSpecial));


%>
<html>
<head>
    <title>修改</title>
</head>
<body>
<form method="post" name="form1" action="haohanbangvue.jsp">
    序号:<input name="id"  id="id" type="text" value="<c:out value="${id}"/>"/>
    姓名:<input name="name" id="name" type="text" value="<c:out value="${name}"/>"/>
    <button type="submit">提交</button>
</form>
</body>
</html>
